﻿using System.Collections.Generic;
using System.Linq;
using Dapper;
using ZilLion.Service.Crm.CommonRepository;
using ZilLion.Service.WechatService.Domain.WebApiEntity.CRM;
using ZilLion.Service.WechatService.Domain.WebApiRepository.InterFace;

namespace ZilLion.Service.WechatService.Domain.WebApiRepository
{
    public class CrmSettingRepository : CrmSqlServerRespository<KzSettingModel>, ICrmSettingRepository
    {
        public CrmSettingRepository() : base(new WechatServiceContext())
        {
        }

        public KzSettingModelResponse GetKzSettingModel()
        {
            KzSettingModel reCard = new KzSettingModel();
            DynamicParameters p = CreateDynamicParameters();
            List<KzSettingModel> items = ExecuteProcWithTemptable(reCard, "pr_jltycrmkykzt_query", "#jltycrmkykzt", false, p).ToList();
            KzSettingModelResponse response=new KzSettingModelResponse() { KzSettings = items };
            return response;
        }

        public ZklbSettingResponse GetZklbSettingModel()
        {
            ZklbSettingModel reCard = new ZklbSettingModel();
            DynamicParameters p = CreateDynamicParameters();
            List<ZklbSettingModel> items = ExecuteProcWithTemptable(reCard, "pr_jltycrmkyzklbt_query", "#jltycrmkyzklbt", false, p).ToList();
            ZklbSettingResponse response = new ZklbSettingResponse() { ZklbSettings = items };
            return response;
        }

        public KzSettingModel SaveKzSettingModel(KzSettingModel kzSetting)
        {
            DynamicParameters p = CreateDynamicParameters();
            KzSettingModel item = ExecuteProcWithTemptable(kzSetting, "pr_jltycrmkykzt_save", "#jltycrmkykzt", true, p).FirstOrDefault();
            return ReturnResponseResultInfo<KzSettingModel>(p) ?? item ?? new KzSettingModel();
        }

        public ZklbSettingModel SaveZklbSettingModel(ZklbSettingModel zklbSetting)
        {
            DynamicParameters p = CreateDynamicParameters();
            ZklbSettingModel item = ExecuteProcWithTemptable(zklbSetting, "pr_jltycrmkyzklbt_save", "#jltycrmkyzklbt", true, p).FirstOrDefault();
            return ReturnResponseResultInfo<ZklbSettingModel>(p) ?? item ?? new ZklbSettingModel();
         }

    }
}
